import { multipleUpdateFreePercentage } from '@/api/network'
import { ref } from 'vue'

export default () => {
  const updateLoading = ref(false)
  const updateForm = ref<{
    freeAmountPercentage: string
    networkIds: Array<string>
  }>({
    freeAmountPercentage: '',
    networkIds: [],
  })

  const update = async () => {
    try {
      updateLoading.value = true
      const res = await multipleUpdateFreePercentage(
        updateForm.value.freeAmountPercentage,
        updateForm.value.networkIds,
      )
      updateLoading.value = false
      return res.data
    } catch (error) {
      updateLoading.value = false
    }
  }

  const resetUpdateForm = () => {
    updateForm.value = {
      freeAmountPercentage: '',
      networkIds: [],
    }
  }

  return {
    updateForm,
    updateLoading,
    update,
    resetUpdateForm,
  }
}
